﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace Win7RovMobileApp
{
    public partial class InvoiceDetails : PhoneApplicationPage
    {
        public InvoiceDetails()
        {
            InitializeComponent();
            DataContext = App.UserPreferences;
            Height = 768; Width = 480;
        }


        private void GotoCardDetails_Click(object sender, RoutedEventArgs e)
        {
            //vital INVOICE information must be presented
            if (String.IsNullOrWhiteSpace(App.UserPreferences.Email) || String.IsNullOrWhiteSpace(App.UserPreferences.VehiclePlate)
                || String.IsNullOrWhiteSpace(App.UserPreferences.OwnerName) || String.IsNullOrWhiteSpace(App.UserPreferences.OwnerAlias))
            {
                MessageBox.Show("Va rugam completati datele din campurile cu *. Acestea sunt necesare facturarii si inregistrarii oficiale a platii!");
                return;
            }

            //vital CARD information must be presented
            if (String.IsNullOrWhiteSpace(App.UserPreferences.CardOwner))
            {
                MessageBox.Show("Va rugam completati numele proprietarului cardului!");
                return;
            }

            if ((String.IsNullOrWhiteSpace(App.UserPreferences.CardSecurityNumber) || (App.UserPreferences.CardSecurityNumber.Length < 3)) && (App.UserPreferences.CardType != "Maestro"))
            {
                MessageBox.Show("Va rugam introduceti codul de securitate al cardului, de trei cifre! Acesta nu va fi retinut, ci doar folosit pentru validarea platii.");
                return;
            }

            if (String.IsNullOrWhiteSpace(App.UserPreferences.CardNumber) || App.UserPreferences.CardNumber.Contains(" ") || App.UserPreferences.CardNumber.Contains("-"))
            {
                MessageBox.Show("Numarul cardului trebuie scris fara spatii sau liniute. Sunt acceptate doar cifre.");
                return;
            }

            App.UserPreferences.ClientType = (PersonType.SelectedItem as ListPickerItem).Content as String;
            NavigationService.Navigate(new Uri("/Menus/ConfirmationScreen.xaml", UriKind.Relative));
        }


        private void SetCardType(object sender, SelectionChangedEventArgs e)
        {
            App.UserPreferences.CardType = ((sender as ListPicker).SelectedItem as ListPickerItem).Content as String;
        }
    }
}